﻿using System;
using System.Collections.Generic;
using Tools.Domain.Specifications;
using Tools.Domain.Specifications.Constraints;
using Webshop20.Domain.Customers.Core;
using Webshop20.Domain.Model.Customers;
using Webshop20.Domain.Orders.Core;
using Webshop20.Domain.Orders.Enumerations;
using Webshop20.Domain.Shared.Payment.Core;
using Webshop20.Model.Orders.Specifications;


namespace Webshop20.UnitTests.Builder
{
    public class BuildOrder
    {
        private int orderId = 1;
      
        private List<Position> positions = new List<Position>() { new Position()};
        private ISpecification<Order> invoiceSpecification = new OpenInvoiceSpecification();

        private IConstraintSet<Order> orderConstraintSet =
            new BuildConstraintSet<Order>().WithInvariantValidationSuccess(new Order()).Build();
        private OrderState state;
        private DateTime date;
        private OrderAdress deliveryAdress = new OrderAdress();
        private IPayment payment = new DirectDebit();
        private OrderAdress billingAdress = new OrderAdress();
        private int customerID = 123;
        private string eMail = "mustermann@musterhost.uu";
        private bool isPayed;

        public BuildOrder WithPaymentMethod(IPayment payment)
        {
            this.payment = payment;
            return this;
        }

        private Order Build()
        {
            return new Order(orderId, customerID, state, date, deliveryAdress, billingAdress, payment, positions, eMail, isPayed, orderConstraintSet);
        }

        public static implicit operator Order(BuildOrder buildOrder)
        {
            return buildOrder.Build();
        }

        public BuildOrder WithIsPayed(bool isPayed)
        {
            this.isPayed = isPayed;
            return this;
        }

        public BuildOrder WithDeliveryAdress(OrderAdress adress)
        {
            deliveryAdress = adress;
            return this;
        }

        public BuildOrder WithOrderDate(DateTime date)
        {
            this.date = date;
            return this;
            
        }

        public BuildOrder WithCustomerId(int customerId)
        {
            this.customerID = customerId;
            return this;
        }

        public BuildOrder WithPositions(List<Position> positions)
        {
            this.positions = positions;
            return this;
        }
    }
}